# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: leon

import decimal

from coin.exchange.base.kr_rest.product_info import ProductInfo, ProductHolder
from coin.exchange.hitbtc_v2.kr_rest.product import HitbtcProduct
from coin.exchange.hitbtc_v2.kr_rest.constants import product_precision
from coin.exchange.hitbtc_v2.config import group_symbol


def get_holder_from_product(product):
  assert isinstance(product, HitbtcProduct)
  price_ticksize, qty_ticksize = product_precision[product.native_symbol]
  price_precision = abs(decimal.Decimal(price_ticksize).as_tuple().exponent)
  qty_precision = abs(decimal.Decimal(qty_ticksize).as_tuple().exponent)
  product_info = ProductInfo(price_precision=price_precision, qty_precision=qty_precision)

  return ProductHolder(product, product_info)


if __name__ == '__main__':
  for group, symbols in group_symbol.items():
    for symbol in symbols:
      product = HitbtcProduct.FromStr(symbol)
      holder = get_holder_from_product(product)
      print(product.full_symbol,
            holder.product_info.price_precision,
            holder.product_info.qty_precision)
